<div id="content">
  <div id="content-header">
    <div id="breadcrumb"> 
        <a href="#" class="tip-bottom" data-original-title="Go to Home"><i class="icon-home"></i> 首页</a> 
        <a href="#" class="tip-bottom" data-original-title="">管理</a> 
        <a href="#" class="current">签约主播</a> 
    </div>
    
   <!--  <h1>Tables</h1> -->
  </div>
  <div class="container-fluid">
   <!--  <hr> -->
    <div class="row-fluid">
      <div class="span12">
        <div class="row-fluid">
            <button id="btnadd" class="btn btn-success pull-right">添&nbsp;加</button>
        </div>
        <div class="widget-box">
          <div class="widget-title"> <span class="icon"> <i class="icon-th"></i> </span>
            <h5>签约主播列表</h5>
          </div>
          <div class="widget-content nopadding">
            <table id="dataList" class="table table-bordered table-striped">
              <thead>
                <tr>
                  <th>用户ID</th>
                  <th>家族ID</th>
                  <th>是否家族长</th>
                  <th>真实姓名</th>
                  <th>性别</th>
                  <th>照片</th>
                  <th>籍贯</th>
                  <th>生日</th>
                  <th>开户银行</th>
                  <!--<th>开户行支行信息</th>-->
                  <th>银行卡号</th>
                  <th>开户名字</th>
                  <th>身份证号</th>
                  <th>电话号码</th>
                  <th>QQ</th>
                  <th>住址</th>
                  <th>状态</th>
                  <th>创建时间</th>
                  <th>操作</th>
                </tr>
              </thead>
              <tbody>
                        
              </tbody>
            </table>
          </div>
        </div>

        <div class="row-fluid">
            <div id="pagination" class="pagination alternate pull-right">
              
            </div>
        </div>

        </div>
      </div>
    </div>
  </div>
</div>

<div id="dialog-form" title="Create new user" style=" display: none;">
    <p class="validateTips"></p>
    <div id="userinfoedit">
        <form id="submitform" action="#" method="post" class="form-horizontal">
            <input type="hidden" id="d_uid">

            <table >
                <tr>
                    <td>
                        <div class="control-group">
                            <label class="control-label">用户ID :</label>
                            <div class="controls">
                                <input name="uid" type="text" class="span11">
                            </div>
                        </div>
                    </td>
                    <td>
                        <div class="control-group">
                            <label class="control-label">家族ID:</label>
                            <div class="controls">
                                <input name="familyId" type="text" class="span11">
                                <span class="help-block"></span>
                            </div>
                        </div>
                    </td>
                </tr>

                

                <tr>
                    <td>
                        <div class="control-group">
                            <label class="control-label">真实姓名 :</label>
                            <div class="controls">
                                <input name="realName" type="text" class="span11">
                                <span class="help-block"></span>
                            </div>
                        </div>
                    </td>
                    <td>
                        <div class="control-group">
                            <label class="control-label">性别 :</label>
                            <div class="controls">
                                <select name="gender" class="span11">
                                    <option value="0">女</option>
                                    <option value="1">男</option>
                                </select>
                                <span class="help-block"></span>
                            </div>
                        </div>
                    </td>
                </tr>

                <tr>
                  <td>
                    <div class="control-group">
                        <label class="control-label">籍贯 :</label>
                        <div class="controls">
                            <input name="birth" type="text" class="span11" placeholder="">
                            <span class="help-block"></span>
                        </div>
                    </div>
                  </td>
                  <td>
                      <div class="control-group">
                          <label class="control-label">住址 :</label>
                          <div class="controls">
                              <input name="address" type="text" class="span11">

                              <span class="help-block"></span>

                          </div>
                      </div>
                  </td>
                </tr>

                <tr>
                  <td>
                      <div class="control-group">
                          <label class="control-label">开户银行 :</label>
                          <div class="controls">
                              <input name="bank" type="text" class="span11" placeholder="">
                              <span class="help-block"></span>
                          </div>
                      </div>
                  </td>
                  <td>
                      <div class="control-group">
                          <label class="control-label">银行卡号 :</label>
                          <div class="controls">
                              <input name="cardNumber" type="text" class="span11">
                              <span class="help-block"></span>
                          </div>
                      </div>
                  </td>
                </tr>

                <tr>
                  <td>
                      <div class="control-group">
                          <label class="control-label">开户名字 :</label>
                          <div class="controls">
                              <input name="accountName" type="text" class="span11" placeholder="">
                          </div>
                      </div>
                  </td>
                  <td>
                      <div class="control-group">
                          <label class="control-label">身份证号 :</label>
                          <div class="controls">
                              <input name="idCard" type="text" class="span11">
                              <span class="help-block"></span>
                          </div>
                      </div>
                  </td>
                </tr>

                <tr>
                  <td>
                      <div class="control-group">
                          <label class="control-label">电话号码 :</label>
                          <div class="controls">
                              <input name="telephone" type="text" class="span11">
                          </div>
                      </div>
                  </td>
                  <td>
                      <div class="control-group">
                          <label class="control-label">QQ :</label>
                          <div class="controls">
                              <input name="qq" type="text" class="span11">
                              <span class="help-block"></span>
                          </div>
                      </div>
                  </td>
                </tr>

                <tr>
                  <td>
                      <div class="control-group">
                          <label class="control-label">照片 :</label>
                          <div class="controls">
                              <input name="photo" type="text" class="span11" placeholder="">
                              <span class="help-block"></span>
                          </div>
                      </div>
                  </td>
                  <td>
                      <div class="control-group">
                          <label class="control-label">出生年月 :</label>
                          <div class="controls">
                              <input id="birthday" name="birthday" type="text" class="laydate-icon span11">
                              <span class="help-block"></span>
                          </div>
                      </div>
                  </td>
                </tr>

                <tr>
                  <td>
                      <div class="control-group">
                        <label class="control-label">状态 :</label>
                        <div class="controls">

                          <select name="status" class="span11">
                              <option value="0">未审批</option>
                              <option value="1">正常</option>
                          </select>                            

                          <span class="help-block"></span>

                        </div>
                      </div>
                  </td>

                  <td>
                    <div class="control-group">
                        <label class="control-label">是否是家族长:</label>
                        <div class="controls">
                            <select name="isFamilyCreator" class="span11">
                                <option value="0">是</option>
                                <option value="1">否</option>
                            </select>
                           <!--  <input name="isFamilyCreator" type="text" class="span11"> -->
                            <span class="help-block"></span>
                        </div>
                    </div>
                </td>
                </tr>
            </table>

        </form>
    </div>
</div>

<script type="text/javascript">

$(function(){
  getDataList();
  
  laydate.skin('molv');

  laydate({
     elem: '#birthday'
  });
});

/**
* 初始化为空
*/
function Initialization(){

  var submitform=document.getElementById('submitform');
    
    submitform.uid.value='';
    submitform.familyId.value='';
    submitform.isFamilyCreator.value='';
    submitform.realName.value='';
    submitform.gender.value='';
    submitform.photo.value='';
    submitform.bank.value='';
    submitform.birth.value='';
    submitform.cardNumber.value='';
    submitform.accountName.value='';
    submitform.idCard.value='';
    submitform.telephone.value='';
    submitform.qq.value='';
    submitform.birthday.value='';
    submitform.address.value='';
    submitform.status.value='';
}

 var btnadd=document.getElementById('btnadd');
 utils.addEvent(btnadd,'click',addData);

 function addData(){
  $( "#dialog-form" ).dialog({
      width: 700,
      title:'添加签约主播',
      modal:true,
      closeOnEscape:true,
      resizable:false,
      open:function(res){
          Initialization();
        },
      buttons:{
        "添加":function(){

          var submitform=document.getElementById('submitform');
          
          data={};

          data.action="add"
          data.uid=submitform.uid.value;
          data.familyId=submitform.familyId.value;
          data.isFamilyCreator=submitform.isFamilyCreator.value;
          data.realName= submitform.realName.value;
          data.gender= submitform.gender.value;
          data.photo= submitform.photo.value;
          data.bank= submitform.bank.value;
          data.birth= submitform.birth.value;
          data.cardNumber=submitform.cardNumber.value;
          data.accountName= submitform.accountName.value;
          data.idCard= submitform.idCard.value;
          data.telephone= submitform.telephone.value;
          data.qq= submitform.qq.value;
          data.birthday= submitform.birthday.value; 
          data.address= submitform.address.value;
          data.status= submitform.status.value;  

          $.ajax({
              type:"post",
              url:"/familymgr/updateSignAnchor",
              data:data,
              dataType:'json',
              success:function(res){
                if(res.code==0){
                  getDataList();
                  $("#dialog-form" ).dialog("close");
                }else{
                  alert(res.info);
                }
              }
          });

          
        },
        "取消":function(){
          $(this).dialog("close");
        }

      }
  });
 }


function getDataList(index){
  var data={};
  data.page=index||0;
  data.numPerPage=pagesize;
  $.ajax({
    type:"post",
    url:"/familymgr/getSignAnchor",
    data:data,
    dataType:'json',   
    success:function(res){
      
      var data=res.data;
      var table=document.getElementById("dataList");
      var tbody= table.getElementsByTagName('tbody')[0];

      dataTable.clearData(tbody);
      
      for(var i=0;i<data.list.length;i++){
        addRow(tbody,'',data.list[i]);
      }
      
      if(!index||index==0){
        initPagination(data.count);
      }

    }
  });
}

function initPagination(page) {
  $("#pagination").pagination(page, {
      callback: pageselectCallback,
      items_per_page:pagesize, // 每页只显示一条记录
      num_display_entries : 3,
      num_edge_entries : 1, 
      prev_text : "上一页",  
      next_text : "下一页", 
  });
}

function pageselectCallback(page_index, jq){
    getDataList(page_index);
    return false;
}

function addRow(table,index,data){
  var row=table.insertRow();
  var cell=row.insertCell(0);
  var cell1=row.insertCell(1);
  var cell2=row.insertCell(2);
  var cell3=row.insertCell(3);
  var cell4=row.insertCell(4);
  var cell5=row.insertCell(5);
  var cell6=row.insertCell(6);
  var cell7=row.insertCell(7);
  var cell8=row.insertCell(8);
  var cell9=row.insertCell(9);
  var cell10=row.insertCell(10);
  var cell11=row.insertCell(11);
  var cell12=row.insertCell(12);
  var cell13=row.insertCell(13);
  var cell14=row.insertCell(14);
  var cell15=row.insertCell(15);
  var cell16=row.insertCell(16);
  var cell17=row.insertCell(17);

  cell.innerHTML=data.uid;
  cell1.innerHTML=data.familyId;
  cell2.innerHTML=data.isFamilyCreator==0?"是":"否";
  cell3.innerHTML=data.realName;
  cell4.innerHTML=data.gender==0?"女":"男";
  cell5.innerHTML=data.photo;
  cell6.innerHTML=data.birth;
  cell7.innerHTML=new Date(data.birthday*1000).format("yyyy-MM-dd");
  cell8.innerHTML=data.bank;
  cell9.innerHTML=data.cardNumber;
  cell10.innerHTML=data.accountName;
  cell11.innerHTML=data.idCard;
  cell12.innerHTML=data.telephone;
  cell13.innerHTML=data.qq;
  cell14.innerHTML=data.address;
  cell15.innerHTML=data.status==0?"未审批":"正常";
  cell16.innerHTML=new Date(data.createTime*1000).format("yyyy-MM-dd");

  var deit=document.createElement("a"),
  del=document.createElement("a");
  
  deit.innerHTML='编辑';
  deit.className="table-edit";
  deit.data=data.id;
  utils.addEvent(deit,'click',dataEdit);

  del.innerHTML='删除';
  del.data=data.id; 
  utils.addEvent(del,'click',dataDelete); 

  cell17.appendChild(deit);
  cell17.appendChild(del);
    
  return row;
}
  

function dataEdit(){
  var btn=this;  
  var url="/familymgr/updateSignAnchor/"+btn.data;
  
   $( "#dialog-form" ).dialog({
        width: 700,
        title:'修改签约主播',
        modal:true,
        closeOnEscape:true,
        resizable:false,
        open:function(){
          var data={};
          data.action='';

          Initialization();

          $.ajax({
            type:"post",
            data:data,
            url:url,
            dataType:'json',
            success:function(res){
              var data= res.data;

              var submitform=document.getElementById('submitform');

              submitform.uid.value=data.uid;
              submitform.familyId.value=data.familyId;
              submitform.isFamilyCreator.value=data.isFamilyCreator;
              submitform.realName.value=data.realName;
              submitform.gender.value=data.gender;
              submitform.photo.value=data.photo;
              submitform.bank.value=data.bank;
              submitform.birth.value=data.birth;
              submitform.cardNumber.value=data.cardNumber;
              submitform.accountName.value=data.accountName;
              submitform.idCard.value=data.idCard;
              submitform.telephone.value=data.telephone;
              submitform.qq.value=data.qq;
              submitform.birthday.value=new Date(data.birthday*1000).format("yyyy-MM-dd");
              submitform.address.value=data.address;
              submitform.status.value=data.status;
            }
          });
        },
        buttons:{
          "修改":function(){

            var submitform=document.getElementById('submitform');

            data={};
            data.action="update"; 

            data.uid=submitform.uid.value;          //应该是不可编辑
            data.familyId=submitform.familyId.value;
            data.isFamilyCreator=submitform.isFamilyCreator.value;
            data.realName= submitform.realName.value;
            data.gender= submitform.gender.value;
            data.photo= submitform.photo.value;
            data.bank= submitform.bank.value;
            data.birth= submitform.birth.value;
            data.cardNumber=submitform.cardNumber.value;
            data.accountName= submitform.accountName.value;
            data.idCard= submitform.idCard.value;
            data.telephone= submitform.telephone.value;
            data.qq= submitform.qq.value;
            data.birthday= new Date(submitform.birthday.value).getTime()/1000;
            data.address= submitform.address.value;
            data.status= submitform.status.value;  

            $.ajax({
              type:"post",
              data:data,
              url:url,
              dataType:'json',
              success:function(res){
                if(res.code==0){
                  getDataList();
                  $("#dialog-form" ).dialog("close");
                }else{
                  alert(res.info);
                }       
              }
            });

          },
          "取消":function(){
            $(this).dialog("close");
          }

        }
   });

}

function dataDelete(){
  if(confirm("确定要删除该数据")){
    var btn=this;  
    var url="/familymgr/updateSignAnchor/"+btn.data,
    data={};
    data.action="del";
    $.ajax({
      type:"post",
      data:data,
      url:url,
      dataType:'json',
      success:function(res){
        if(res.code==0){
          getDataList();
         //dataTable.delTableRow(btn);
        }else{
          alert(res.info);
        }      
      }
    });
  }
}

</script>
